<div ng-include="sys_html('common/_header','','','jy_weishop')"></div>
<style>
    .yen{border:none;height:0.75rem;width:0.75rem;display: inline-block;background: #ff4753;color:#fff;font-size:0.4rem;line-height: 0.8rem;text-align: center;
        font-style: normal;border-radius: 0.75rem;-webkit-border-radius: 0.75rem;}
    .order-create-page .fui-list.goods-item .fui-list-inner{
        height: 3.5rem;
        align-self: center;
    }
    .order-create-page .fui-list.goods-item .fui-list-angle{
        height: 3.5rem;
        align-self: center;
    }
    .order-create-page .fui-list-inner .subtitle{
        display: block;
    }
    .fui-header a.back2:before {
        content: " ";
        display: inline-block;
        -webkit-transform: rotate(45deg);
        -ms-transform: rotate(45deg);
        transform: rotate(45deg);
        height: 0.5rem;
        width: 0.5rem;
        border-width: 0 0 2px 2px;
        border-color: #666;
        border-style: solid;
        position: relative;
        top:0;
    }
.fui-btn-c {
    height: auto;
    margin: 0;
    padding: 0.4rem;
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-align: center;
    -webkit-align-items: center;
    -ms-flex-align: center;
	justify-content:center;
    align-items: center;
    position: relative;
}

.fui-btn-c .icon {
	font-size:1rem;
	padding-right:0.3rem;
	text-align:right;
}

.fui-btn-c .info {
	text-align:left;
    padding-right: 0.2rem;
    font-size: 0.75rem;
}

.fui-btn-c .info p {
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
}
.jylabel-red-0.active::after{content:" ";width:23px;height:24px;background:url(../core/resource/images/gou-red.png) no-repeat;position:absolute;float:right;right:-1px;bottom:-1px;text-align:center;}
.fui-number .minus:before, .fui-number .plus:before {
	border-left: 0 solid #d9d9d9;
}
.fui-number .minus:after, .fui-number .plus:after {
	border-right: 0 solid #d9d9d9;
}
.fui-number:before {
	border-top: 0 solid #d9d9d9;
}
.fui-number:after {border-top: 0 solid #d9d9d9;}
.fui-number .num {
	color:#666;
}
.fui-number .num {
	color:#666;
}
.fui-number.small {
	height: 1.2rem;
	width: 3.6rem;
	line-height: 1.2rem;
}
.fui-number .minus, .fui-number .plus {
	z-index:0;
}
.fui-number.small .minus{
	color: {{main.syscolor || '#63BE72'}};
	padding-top:1px;
	border: 1px solid {{main.syscolor || '#63BE72'}};
	border-radius:50%;
}
 .fui-number.small .plus {
	color: #fff;
	padding-top:1px;
	background: {{main.syscolor || '#63BE72'}};
	border: 1px solid {{main.syscolor || '#63BE72'}};
	border-radius:50%;
}
.fui-navbar .cartbtn {padding-right:0.3rem;background:#fff;opacity:1}
.fui-navbar .buybtn  {padding-left:0.3rem;background:#fff}
.fee-tag-nav, .fee-tagup-nav, .fee-disabled-nav ,.fee-tag-nav-o {border-radius:1rem;height:2rem;line-height:2rem;color:#fff;width:100%;font-weight:400;font-size:0.7rem;margin:0.2rem 0;padding:0 0.2rem}
.fee-tagup {background:{{main.syscolor || 'red'}};color:#fff;width:auto;font-weight:400;font-size:0.55rem}
.fee-tag-nav {background:{{main.syscolor || 'red'}}; opacity: 0.58;}
.fee-tagup-nav {background:{{main.syscolor || 'red'}};}
.fee-disabled-nav {background:#bbb;color:#fff;}	
.fee-tag-nav-o {background:#fff;color:{{main.syscolor || 'red'}};border: 1px solid {{main.syscolor || 'red'}};}
.coutag {padding:0.1rem 0.2rem;background:#ffedef;color:#db2e2a;font-size:0.55rem;border-radius: 0.2rem;}
</style>
<div class='fui-page order-create-page' ng-if="pagedata.nodatapic_close">
    <div class='fui-content'>
	<div class='jy-content'>
	<div ng-if="pagedata.order.oldorderid" class="radius" style="background:#fff;margin-top:0.3rem">
	<div class="fui-cellone">
		<div class="fui-cellone-label bold" style="width:auto;font-size:0.75rem">已点商品明细</div>
		<div class="fui-cellone-info"><span style="padding-left:0.3rem">桌位号：桌台{{pagedata.table.title}}</span></div>
		<div class="fui-cellone-remark noremark"></div>
	</div>
	<div ng-repeat="item in pagedata.grouplistold" class="fui-list-group"  style="margin-top:0">
	<div class="fui-cell-title bold c" style="padding: 0.5rem 0.65rem;">— {{item.title}} —</div>
	<div ng-repeat="g in item.list" class="fui-list goods-item align-start">
        <div class="fui-list-media">
            <img class="round" ng-src="{{tomedia(g.image)}}">
        </div>
        <div class="fui-list-inner" style="height:auto">
            <div>
                <div class="subtitle">{{g.title}}</div>
                <div class="text" style="font-size:0.5rem" ng-if="g.optionid">{{g.optiondata || '默认规格'}}</div>
            </div>
			<!--配送区域完成-->
			<div ng-if="g.has_city==1" class='subtitle' style="color:#999">
				<span ng-if="g.isdispatcharea==0" class='fui-cell-label' style="width:auto">不配送区域:</span>
				<span ng-if="g.isdispatcharea!=0" class='fui-cell-label' style="width:auto">只配送区域:</span>
				<span ng-repeat="(ke,v) in g.citys" class="fui-tag fui-tag-red-o sale-tip">{{ke}}</span>
			</div>
			<div class='price'>
				<span class="bigprice text-danger">￥<span ng-if="!g.active.price" class='marketprice'>{{g.price}}</span><span ng-if="g.active.price" class='marketprice'>{{g.active.price}}</span> <span ng-if="g.active.title" class='red' style="font-size:0.65rem;font-weight:400"> {{g.active.title}}</span> <span ng-if="g.buyxiu_de_price>0" style="font-size:0.65rem;font-weight:400" class='red'>买家秀 -￥{{g.buyxiu_de_price}}</span></span>
				<span class="num bold">x {{g.total}}</span>
			</div>
        </div>
    </div>
	</div>
	</div>
	<div ng-if="pagedata.order.cart_num>0" class="radius" style="background:#fff;margin-top:0.3rem">
	<div class="fui-cellone">
		<div class="fui-cellone-label bold" style="width:auto;font-size:0.75rem">{{pagedata.order.oldorderid?'追加':''}}商品明细</div>
		<div class="fui-cellone-info" style="padding-left:0.5rem;" ng-if="pagedata.table.title"><span>桌位号：桌台{{pagedata.table.title}}</span></div>
		<div class="fui-cellone-remark noremark">
			<i ng-if="!pagedata.showdel" class="icon icon-delete syscolor" ng-click="pagedata.showdel=true"></i>
			<i ng-if="pagedata.showdel" class="icon icon-dingdan syscolor" ng-click="pagedata.showdel=false"></i>
		</div>
	</div>
	<div ng-repeat="(mk,item) in pagedata.grouplist" class="fui-list-group" style="margin-top:0">
	<div class="fui-cell-title bold c" style="padding: 0.5rem 0.65rem;">— {{item.title}} —</div>
    <div ng-repeat="g in item.list" class="fui-list goods-item align-start">
        <div class="fui-list-media">
            <img class="round" ng-src="{{tomedia(g.image)}}">
        </div>
        <div class="fui-list-inner" style="height:auto">
            <div>
                <div class="subtitle">{{g.title}}</div>
                <div class="text" style="font-size:0.5rem" ng-if="g.optionid">{{g.optiondata || '默认规格'}}</div>
				<span ng-if="pagedata.order.gamelogid>0" class="fui-tag fui-tag-red sale-tip">活动兑换</span>
            </div>
			<!--配送区域完成-->
			<div ng-if="g.has_city==1" class='subtitle' style="color:#999">
				<span ng-if="g.isdispatcharea==0" class='fui-cell-label' style="width:auto">不配送区域:</span>
				<span ng-if="g.isdispatcharea!=0" class='fui-cell-label' style="width:auto">只配送区域:</span>
				<span ng-repeat="(ke,v) in g.citys" ng-if="ke" class="fui-tag fui-tag-red sale-tip">{{ke}}</span>
			</div>
			<div class='price'>
				<span class="bigprice text-danger">￥<span ng-if="!g.active.price" class='marketprice'>{{g.price}}</span><span ng-if="g.active.price" class='marketprice'>{{g.active.price}}</span> <span ng-if="g.active.title" class='red' style="font-size:0.65rem;font-weight:400"> {{g.active.title}}</span> <span ng-if="g.buyxiu_de_price>0" style="font-size:0.65rem;font-weight:400" class='red'>买家秀 -￥{{g.buyxiu_de_price}}</span></span>
				<div ng-if="!pagedata.showdel" class="fui-number small">
					<div class="minus" ng-click="pagedata.cartminus(mk,$index)"><i class="icon icon-subtract" style="font-size:0.7rem"></i></div>
						<input class="num shownum" type="text" ng-model="g.total" style="width:1rem" readonly/>
					<div class="plus" ng-click="pagedata.cartplus(mk,$index)"><i class="icon icon-tianjia" style="font-size:0.7rem"></i></div>
				</div>
				<div ng-if="pagedata.showdel" class="fui-number small">
					<i class="icon icon-delete syscolor" style="font-size:0.7rem;padding-left:2.5rem" ng-click="pagedata.cartdel(mk,$index)"></i>
				</div>
			</div>
        </div>
    </div>
	</div>
    <script type="text/javascript">
        $(function(){
            $(".package-goods-img").height($(".package-goods-img").width());
        })
    </script>
 
</div>
<div class="fui-cell-group" ng-if="pagedata.gifts.length>0">
    <div ng-repeat="gift in pagedata.gifts" class="fui-cell" style="padding:0 ">
            <div class="fui-list goods-item" style="width:100%;">
                <div class="fui-list-media image-media" style="position: initial;">
                    <a href="javascript:void(0);">
                        <img class="round" ng-src="{{tomedia(gift.image)}}" >
                    </a>
                </div>
                <div class="fui-list-inner">
                    <a href="javascript:void(0);">
                        <div class="text" style="color: #000">
                            {{gift.title}}<br /><span class="fui-label fui-label-danger">赠品</span>
                        </div>
                    </a>
                </div>
                <div class='fui-list-angle' ng-if="gift.price">
                    <span class="price" style="display: inline-block;font-size:.65rem;color: #000 ">&yen;<del class='marketprice'>{{gift.price}}</del></span>
                </div>
            </div>
    </div>
</div>
<div class="fui-cell-group">
				<div class="fui-cellone" style="padding-bottom:0">
					<div class="fui-cellone-label bold" style="width:100px;">备注</div>
				</div>
				<div class="fui-cell">
					<div class="fui-cell-info">
						<textarea rows="2" placeholder="50字以内（选填）" ng-model="pagedata.post.remark"></textarea>
					</div>
				</div>
</div>
</div>
</div>
</div>
<div class="fui-navbar order-create-checkout">
    <a href="javascript:;" class="nav-item total" style="text-align:left;padding-left:0.5rem">
        <span class="text-danger bigprice">&yen; 
			<span class="totalprice" style="font-size:1.2rem">{{price(pagedata.order.total_price) || '0.00'}}</span>
		</span>
    </a>
	<a ng-if="!pagedata.order.id || pagedata.order.status==0" href="javascript:;" class="nav-item btn buybtn" ng-click="access_json('jy_merchcmi/myshop//id='+pagedata.order.merchid+'&orderid='+pagedata.order.id);">	
		<div class="fee-tag-nav-o">
			{{(!pagedata.order.id || pagedata.order.cart_num>0)?'返回看看':'追加+'}}
		</div>
	</a>
    <a href="javascript:;" class="nav-item btn buybtn" ng-if="!pagedata.order_id && ((pagedata.order.no_out_price==0 && pagedata.order.outarea!=1) || pagedata.post.sendtype!=1)" ng-click="pagedata.post_check()" >
		<div class="fee-tagup-nav">
			{{pagedata.is_moregoods==1?'确认下单':'支付并下单'}}
		</div>
	</a>
	<a ng-if="pagedata.order.id && pagedata.order.cart_num>0" href="javascript:;" class="nav-item btn btn-danger buybtn" ng-click="pagedata.post_check()" >
		<div class="fee-tagup-nav">
			确认追加
		</div>
	</a>
	<a ng-if="pagedata.order.id && (pagedata.order.cart_num<=0||!pagedata.order.cart_num)" href="javascript:;" class="nav-item btn btn-danger buybtn" ng-click="access_json('/order.create//id='+pagedata.order.id)" >
		<div class="fee-tag-nav">
			支付订单
		</div>
	</a>
</div>
</div>
<div ng-include="sys_html('common/_footer')"></div>
<script language='javascript'>
scope.pagedata.setting=scope.pagedata.setting?scope.pagedata.setting:{}
//减少
scope.pagedata.cartminus=function(mk,index){
	var cart=scope.pagedata.grouplist[mk]['list'][index]
	scope.post_json('jy_weishop/member.cart/minus/',{'id':cart.cartid},function(){
				if(cart.total==1){
					scope.pagedata.grouplist[mk]['list'].splice(index,1);
				}
				cart.total--;
				if(cart.outtype==1 && cart.total + cart.order_goodscount<=cart.usermaxbuy){
					cart.outtype=false;
				}
				if(cart.outtype==2 && cart.total<=cart.kucun){
					cart.outtype=false;
				}
				if(cart.outtype==4 && cart.total<=cart.maxbuy){
					cart.outtype=false;
				}
				if(cart.outtype==5 && cart.total<=cart.active.maxnum){
					cart.outtype=false;
				}
				scope.pagedata.cart=cart;
				scope.pagedata.refresh();
				if(cart.total==0){
					scope.message('删除成功！');
				}else{
					scope.message('减少成功！');
				}
				scope.$evalAsync();
	})
}
//增加
scope.pagedata.cartplus=function(mk,index){
	var cart=scope.pagedata.grouplist[mk]['list'][index]
	if(cart.kucun<=cart.total){
		scope.message('超库存，不能再加了！');
		return false;
	}
	scope.post_json('jy_weishop/member.cart/plus/',{'id':cart.cartid},function(res){
			if(res=='success'){
				cart.total++;
				if(cart.outtype==3 && cart.total>=cart.minbuynum){
					cart.outtype=false;
				}
				scope.message('添加成功！');
				scope.pagedata.refresh();
				scope.$evalAsync();
			}else{
				scope.message('添加失败:'+res);
			}
	});
}
//删除
scope.pagedata.cartdel=function(mk,index){
	var cart=scope.pagedata.grouplist[mk]['list'][index]
	scope.post_json('jy_weishop/member.cart/del/id='+cart.cartid,{'id':cart.cartid},function(res){
			scope.pagedata.grouplist[mk]['list'].splice(index,1);
			scope.message('删除成功！');
			scope.pagedata.refresh();
			scope.$evalAsync();
	});
}
//刷新总数和总价
scope.pagedata.refresh=function(){
	var total=0,totalprice=0.00;
	scope.pagedata.isselectall=1;
	for(var i=0;i<scope.pagedata.grouplist.length;i++){
		var merch=scope.pagedata.grouplist[i]
		//console.log(merch)
	   angular.forEach(merch.list,function(cart){
			cart.total=parseInt(cart.total);
			totalprice+=cart.total*cart.price;
			//console.log(cart.price)
		});
	}
	var totalprice = totalprice.toString(); //将数字转换为字符串
	var pos_decimal = totalprice.indexOf('.'); //小数点的索引值
	 // 当整数时，pos_decimal=-1 自动补0  
	if (pos_decimal < 0) {  
			pos_decimal = totalprice.length;  
			totalprice += '.';  
	}
	// 当数字的长度< 小数点索引+2时，补0  
	while (totalprice.length <= pos_decimal + 2) {  
			totalprice += '0';  
	}
	scope.pagedata.order.total=total;
	scope.pagedata.order.total_price=totalprice;
}
scope.pagedata.post_check=function(orderid){
    scope.post_json('jy_merchcmi/order.check/post/is_moregoods='+scope.pagedata.is_moregoods,scope.pagedata.post,function(res){
		scope.pagedata.order_id=res.order_id
		scope.message('下单成功！');
	});
}
scope.pagedata.pay_check=function(orderid){
    var onemerchid=scope.pagedata.onemerchid;
	if(scope.pagedata.order.sendtype==1){
		scope.pay_submit({},'jy_merchcmi/order.create/pay/id='+orderid,'jy_merchcmi/order.list//id='+orderid,'',onemerchid);
		return true;
	}
	scope.confirm({
		'message':'确认要现在买单吗？可以就餐后再买单的！',
		'success':function(){
			scope.pay_submit({},'jy_merchcmi/order.create/pay/id='+orderid,'jy_merchcmi/order.list//id='+orderid,'',onemerchid);
		},
		'fail':function(){}
	});
}
</script>
